import random

def generate_input(n):
    """生成测试输入数据"""
    return n

import random

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def generate_tree(n):
    if n == 0:
        return None
    nodes = [TreeNode(i) for i in range(1, n+1)]
    random.shuffle(nodes)
    root = nodes[0]
    for node in nodes[1:]:
        current = root
        while True:
            if random.random() < 0.5:
                if current.left is None:
                    current.left = node
                    break
                else:
                    current = current.left
            else:
                if current.right is None:
                    current.right = node
                    break
                else:
                    current = current.right
    return root

def tree_to_preorder(root):
    return [] if root is None else [root.val] + tree_to_preorder(root.left) + tree_to_preorder(root.right)

def tree_to_inorder(root):
    return [] if root is None else tree_to_inorder(root.left) + [root.val] + tree_to_inorder(root.right)

def generate_test_case(n):
    tree = generate_tree(n)
    return tree_to_preorder(tree), tree_to_inorder(tree)

if __name__ == "__main__":
    preorder, inorder = generate_test_case(5)
    print(f"Preorder: {preorder}")
    print(f"Inorder: {inorder}")    